import quotationDict from "@/dict/quotation";

export const modifyPrice = {
  data() {
    return {
      modifyPrice: ""
    };
  },
  methods: {
    // 提交价格修改
    modifyPriceHandle(type, request, isLine) {
      const h = this.$createElement;
      let _this = this;
      this.$confirm({
        title: "订单修改价格",
        icon: "exclamation-circle",
        content: h("div", {}, [
          h(
            "p",
            {
              style: {
                marginTop: "1em"
              }
            },
            `原订单${type === 1 ? "基价" : "含税单价"}：${
              type === quotationDict.priceType.pricing.value
                ? this.orderDetail.basePrice
                : this.orderDetail.firmPrice
            }`
          ),
          h(
            "p",
            {
              className: "flex"
            },
            [
              h(
                "span",
                `修改订单${
                  type === quotationDict.priceType.pricing.value
                    ? "基价"
                    : "含税单价"
                }：`
              ),
              h("a-input", {
                style: {
                  width: "160px"
                },
                attrs: {
                  placeholder: "请输入价格"
                },
                domProps: {
                  value: _this.modifyPrice
                },
                on: {
                  input: function(event) {
                    _this.modifyPrice = event.target.value;
                  }
                }
              })
            ]
          )
        ]),
        onOk() {
          return new Promise((resolve, reject) => {
            let params = {
              version: _this.orderDetail.version
            };
            // 点价、确定价传参不同
            params[
              type === quotationDict.priceType.pricing.value
                ? "basePrice"
                : "firmPrice"
            ] = _this.modifyPrice;
            params[isLine ? "id" : "orderId"] = _this.orderDetail.id;
            request(params)
              .then(res => {
                _this.$message.success("操作成功");
                _this.$emit("handleSuccess", {
                  data: res,
                  type:
                    type === 1
                      ? isLine
                        ? "sellerApplyModifyBasePriceByLine"
                        : "sellerApplyModifyBasePrice"
                      : isLine
                      ? "sellerApplyModifyFirmPriceByLine"
                      : "sellerApplyModifyFirmPrice"
                });
                resolve();
              })
              .catch(() => {
                reject();
              });
          });
        }
      });
    }
  }
};
